<include file="public@header"/>
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:url('index',array('type_id'=>$type_id))}">标签列表</a></li>
			<li><a href="{:url('add',array('type_id'=>$type_id))}">添加标签</a></li>
		<!-- 	<li><a href="{:url('add_all',array('type_id'=>$type_id))}">快速添加</a></li> -->
			<li class="active"><a href="javascript:;">编辑分类</a></li>
		</ul>
		<form method="post" class="form-horizontal js-ajax-forms margin-top-20" action="">
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">上级分类</label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control" name="parent_id" id="parent_id">
						<option value="0">==请选择==</option>
						{$selectCategorys}
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">标签名称<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="name" value="{$data['name']}" required="true">
				</div>
			</div>
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">图片</label>
				<div class="col-md-6 col-sm-10">
					<imagetpl name="img" id="img" value="$data['img']"/>
				</div>
			</div>
			<div class="form-group">
				<label for="input-remark" class="col-sm-2 control-label">备注</label>
				<div class="col-md-6 col-sm-10">
					<label class="radio-inline js-icheck"><input type="radio" name="status" value="1" checked>显示</label>
					<label class="radio-inline js-icheck"><input type="radio" name="status" value="0" <if condition="$data['status'] eq '0'">checked</if>>隐藏</label>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<input type="hidden" name="id" value="{$data.cid}">
					<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
					<a class="btn btn-default" href="{:url('index',['type_id'=>$type_id])}">{:lang('BACK')}</a>
				</div>
			</div>
		</form>
	</div>
	<script src="__STATIC__/js/admin.js"></script>
	<script type="text/javascript">
		$(function() {
			Wind.use('validate', 'ajaxForm', 'artDialog', function() {
				
				var form = $('form.js-ajax-forms');
				
				//ie处理placeholder提交问题
				if ($.browser && $.browser.msie) {
					form.find('[placeholder]').each(function() {
						var input = $(this);
						if (input.val() == input.attr('placeholder')) {
							input.val('');
						}
					});
				}
				
				var formloading = false;
				//表单验证开始
				form.validate({
					//是否在获取焦点时验证
					onfocusout : true,
					//是否在敲击键盘时验证
					onkeyup : false,
					//当鼠标掉级时验证
					onclick : false,
					//验证错误
					showErrors : function(errorMap, errorArr) {
						//errorMap {'name':'错误信息'}
						//errorArr [{'message':'错误信息',element:({})}]
						try {
							$(errorArr[0].element).focus();
							art.dialog({
								id : 'error',
								icon : 'error',
								lock : true,
								fixed : true,
								background : "#CCCCCC",
								opacity : 0,
								content : errorArr[0].message,
								cancelVal : '确定',
								cancel : function() {
									$(errorArr[0].element).focus();
								}
							});
						} catch (err) {
						}
					},
					//验证规则
					rules : {
						'name' : "required",
					},
					//验证未通过提示消息
					messages : {
						'name' : '请输入标签名称',
					},
					//给未通过验证的元素加效果,闪烁等
					highlight : false,
					//是否在获取焦点时验证
					onfocusout : false,
					//验证通过，提交表单
					submitHandler : function(forms) {
						if (formloading)
							return;
						$(forms).ajaxSubmit({
							url : form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
							dataType : 'json',
							beforeSubmit : function(arr, $form, options) {
								formloading = true;
							},
							success : function(data, statusText, xhr, $form) {
								formloading = false;
								console.log(data);
								if (data.code) {
									setCookie("refersh_time", 1);
									//修改成功
									Wind.use("artDialog", function() {
										art.dialog({
											id : "succeed",
											icon : "succeed",
											fixed : true,
											lock : true,
											background : "#CCCCCC",
											opacity : 0,
											content : data.msg,
											button : [ {
												name : '继续修改？',
												callback : function() {
													reloadPage(window);
													return true;
												},
												focus : true
											}, {
												name : '返回列表页',
												callback : function() {
													location = "{:url('index',array('type_id'=>$type_id))}";
													return true;
												}
											} ]
										});
									});
								} else {
									artdialogAlert(data.msg,'succeed');
								}
							}
						});
					}
				});
			});
		});
	</script>
</body>
</html>